using System;

namespace UnitTesting.Fixturing
{
	class ManyValueProvider : IValueProvider, IManyCountSetter
	{
		readonly ArrayValueProvider _arrayValueProvider;
		readonly EnumerableValueProvider _enumerableValueProvider;
		readonly GenericCollectionValueProvider _genericCollectionValueProvider;
		readonly IValueProvider _compositeValueProvidcer;

		public virtual int Count
		{
			set
			{
				_arrayValueProvider.Count = value;
				_enumerableValueProvider.Count = value;
				_genericCollectionValueProvider.Count = value;
			}
		}

		internal ManyValueProvider(IValueProvider valueProvider)
			: this(new ArrayValueProvider(valueProvider),
			       new EnumerableValueProvider(valueProvider),
			       new GenericCollectionValueProvider(valueProvider))
		{
		}

		internal ManyValueProvider(ArrayValueProvider arrayValueProvider,
		                           EnumerableValueProvider enumerableValueProvider,
		                           GenericCollectionValueProvider genericCollectionValueProvider)
		{
			_arrayValueProvider = arrayValueProvider;
			_enumerableValueProvider = enumerableValueProvider;
			_genericCollectionValueProvider = genericCollectionValueProvider;
			_compositeValueProvidcer = new StaticCompositeValueProvider(arrayValueProvider, enumerableValueProvider, genericCollectionValueProvider);
		}

		public virtual object Create(Type type)
		{
			return _compositeValueProvidcer.Create(type);
		}
	}
}